import {  getMenuList } from "@/api/user";

export default {
    state: {
        user: "", // 用户信息
        access: "", // 用户权限
        unreadCount: 3, // 用户未读消息
        hasGetInfo: false, // 获取用户信息是否成功
        loading: false //加载
    },
    actions: {
        getMenuList({ state }) {
            return new Promise((resolve, reject) => {
                try {
                    getMenuList(state.user.roleid)
                        .then(res => {
                            const menuList = res.data
                            const user = { ...state.user, menuList }
                            sessionStorage.setItem('user', JSON.stringify(user))
                            resolve(res)
                        })
                        .catch(err => {
                            reject(err);
                        });
                } catch (error) {
                    reject(error);
                }
            });
        }
    },
    mutations: {
        /* 设置用户id */
        setUser(state, data) {
            state.user = data;
        },
        /* 有没有用户信息 */
        setHasGetInfo(state, status) {
            state.hasGetInfo = status;
        },
    }
};
